package com.itheima.edu.info.manager.day6;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

public class PanDuan {
    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        String s= "2021-5-23";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            calendar.setTime(simpleDateFormat.parse(s));
        } catch (ParseException e) {
            System.out.println("叼你妈的");
        }
        System.out.println(calendar.get((Calendar.DAY_OF_WEEK))-1);



//        Date date=new Date();
//        date.toString("yyyy-MM-dd")


      /*  String s="2018年2月14日 13:14:15";
        DateTimeFormatter date1=DateTimeFormatter.ofPattern("yyyy年M月dd日 HH:mm:ss");
        LocalDate parse1 = LocalDate.parse(s,date1);
       LocalDate parse=parse1;
       parse.getDayOfWeek(parse1);*/
       /* LocalDate d1=LocalDate.of(2018,2,14);
        LocalDate d=LocalDate.of(2018,2,1);
        Period p=Period.between(d,d1);
       int a= (p.getDays()+1)/7;
        System.out.println(a);*/

    }
    public static String dateToWeekday(Date date) throws Exception {
        String[] weekdays = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
        if(date == null) {
            throw new Exception("传入时间为Null");
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int numOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return weekdays[numOfWeek];
    }

}
